﻿using System.Linq;
using System.Net.Http.Formatting;
using System.Web.Http;
using WebApiContrib.Formatting;
using Newtonsoft.Json.Serialization;
using Serilog;

namespace Sustainalytics.ESGRatings.Computing.Service
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            RegisterSerilog();
            //use camel case for json not default pascal case from .NET
            var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().First();
            jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            //all routing will be done through route attributes inside controllers
            config.MapHttpAttributeRoutes();

            config.Formatters.Add(new ProtoBufFormatter());


        }

        public static void RegisterSerilog()
        {
            Log.Logger = new LoggerConfiguration()
                .ReadFrom.AppSettings()
                .Enrich.WithProcessName()
                .Enrich.WithMachineName()
                .CreateLogger();
        }
    }
}